<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>K吧</title>
<link rel="stylesheet" type="text/css" href="<s:property value="staticsRoot"/>/css/front-style.css"/>
<link href="http://www.7k7kjs.cn/qike_public/qike-sns.min.css" rel="stylesheet" />
<script src="http://www.7k7kjs.cn/js/lib/jquery/1.7.2/jquery-min.js"></script>
<script src="http://www.7k7kjs.cn/qike_public/qike-sns.min.js"></script>
<script type="text/javascript" src="<s:property value="staticsRoot"/>/js/jquery-1.8.3.min.js"></script>
<script>document.domain="7k7k.com";</script>
<link rel="stylesheet" type="text/css" href="<s:property value="staticsRoot"/>/css/common.css" media="screen" />
<script type="text/javascript" charset="utf-8" src="<s:property value="staticsRoot"/>/js/kindeditor.js"></script>
<script type="text/javascript" charset="utf-8" src="<s:property value="staticsRoot"/>/js/lang/zh_CN.js"></script>
<script type="text/javascript">
var editor;
$(document).ready(function(){
	$(".mess .i_text").click(function(){
		$(".mess li span").removeClass("dis_none");		
	});
});

KindEditor.ready(function(K) {
	editor = K.create('textarea[id="content"]', {
		allowFileManager : false,
		uploadJson : './upload.html',
		filePostName : 'filedata',
		urlType : 'domain',
		items : [
		'undo', 'redo', 'preview', '|', 
		'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'quickformat', '|',		 
		'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'removeformat', '|', 
		'image', 'insertfile', 'table', 'hr', 'emoticons', 'anchor', 'link', 'unlink','|', 
		'about' 
		]
	});
}); 
</script>
<style type="text/css">
<s:if test="bar.image	!=null	&&	bar.image !='noImage'"> 
body{
	
    background: url(<s:property value="bar.image"/>);
    background-repeat: no-repeat;
    background-position:center top;
   
}
.no-bg {
	background: #fff;
	width: 1210px;
	margin: 0px auto;
}
</s:if>
</style>
</head>

<body>
<s:if test="bar.image	!=null	&&	bar.image !='noImage'"> 
 <div class="no-bg">
 </s:if>
<s:include value="include/header.jsp"/>
<div class="adress">
	<a href='<s:property value="domainRoot"/>/index.html'>k吧</a>&gt;
    <a href='<s:property value="domainRoot"/>/listThread.html?barId=<s:property value="bar.id"/>'><s:property value="bar.name"/></a>&gt;
    <span><s:property value="thread.title" escape="false"/></span>
</div>
<s:action name="top" executeResult="true"/>
<div class="mian">
	<div class="left fl">
		<form name="form1" id="form1" action="listThreadReply.html" method="post">
        <input type="hidden" id ="toPage" name="page" value="<s:property value="queryDO.toPage"/>"/>
		<input type="hidden" name="threadId" value="<s:property value="threadId"/>"/>
		<input type="hidden" id="uId" name="uId" value="<s:property value="uId"/>"/>
    	<ul class="tab_ul">
        	<span>已有<font color="#000000"><s:property value="thread.viewCount"/></font>人浏览，<font color="#000000"><s:property value="thread.replyCount"/></font>人回复
            <s:if test="thread.status == 0"><a href="#replyArea" class="kshf">快速回复</a></s:if>
            <a href="<s:property value="domainRoot"/>/listThread.html?barId=<s:property value="bar.id"/>#publish" class="fbxt">发表新帖</a></span>
        </ul>
  		<table width="100%" cellpadding="0" cellspacing="0" class="tit_table">
        	<tr bgcolor="#f3f3f3">
            	<th width="66%" height="30" align="left" class="tit"><img src="<s:property value="staticsRoot"/>/images/post.png" /><s:property value="thread.title" escape="false"/></th>
                <th width="20%" align="center">发表于:<s:date name="thread.createTime" format="yyyy-MM-dd HH:mm:ss" /></th>
                <th width="14%" align="center"><a href="#" onclick="view('<s:property value="thread.createId"/>')">只看楼主</a></th>
            </tr>
        </table>
        <s:set name="user" value="kbaUser"/>
        <table width="100%" cellpadding="0" cellspacing="0" class="tz">
        	<s:if test="queryDO.isFirstPage() || queryDO.toPage == 0">
            <tr>
            	<td class="border_botm">
                	<table width="100%" cellpadding="0" cellspacing="0">
                    	<tr>
                        	<td width="102" align="left" class="perp" valign="top">
                                <a href="http://my.7k7k.com/space/<s:property value='thread.createId'  />"target="_blank" class="show"><img src="<s:property value='userMap.get(thread.createId).icon_m'/>" /></a>
                                <a href="http://my.7k7k.com/space/<s:property value='thread.createId' />"target="_blank" class="show" ><s:property value="userMap.get(thread.createId).nick"/></a>
                                <!-- 
                                <a href="#" class="gwly">给我留言</a>
                                <span>16经验值</span>
                                <span class="cf">16财富值</span>
                                <span class="dj">LV1</span>
                                 -->
                            </td>
                            <td align="left" class="con" valign="top">
                            	<div id="contentDiv" class="contentDiv">
                                <s:property value="thread.content" escape="false"/>
                                </div>
                                <div class="clearB"></div>
                                <div class="fr">
                                	<!-- 判断是否登录，并且是管理员或者吧主 -->                               	
       								<s:if test="#user.userId == thread.createId">
       								|
       								<a href="editThread.html?threadId=<s:property value="thread.id"/>">编辑</a>
       								</s:if>
       								<s:if test="#user != null && (#user.adminRole == 1 || #user.getBarRoleByBarId(thread.barId))">
                                	|
                                	<s:if test="thread.sticky == 0">
                                	<a href="#" id="sticky" onclick="doThreadOper(0,1);">置顶</a>
                                	</s:if>
                                	<s:else>
                                	<a href="#" id="sticky" onclick="doThreadOper(0,0);">取消置顶</a>
                                	</s:else>
                                	|
                                	<s:if test="thread.digest == 0">
                                	<a href="#" id="digest" onclick="doThreadOper(1,1);">加精</a>
                                	</s:if>
                                	<s:else>
                                	<a href="#" id="digest" onclick="doThreadOper(1,0);">取消加精</a>
                                	</s:else>
                                	|
                                	<s:if test="thread.status == 0">
                                	<a href="#" id="lock" onclick="doThreadOper(2,1);">锁定</a>
                                	</s:if>
                                	<s:else>
                                	<a href="#" id="lock" onclick="doThreadOper(2,0);">取消锁定</a>
                                	</s:else>
                                	|
                                	<s:if test="thread.deleted == 0">
                                	<a href="#" id="deleteThread" onclick="doThreadOper(3,1);">删除</a>
                                	</s:if>
                                	<s:else>
                                	<a href="#" id="deleteThread" onclick="doThreadOper(3,0);">删除恢复</a>
                                	</s:else>
                                	</s:if>
                                	<s:if test="thread.status == 0"><a href="#replyArea"><img src="<s:property value="staticsRoot"/>/images/T1i7W4XiFlXXXXXXXX-73-28.gif" /></a></s:if>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            </s:if>
            <s:iterator var="threadReply" value="list">
            <tr>
            	<td class="border_botm">
                	<table width="100%" cellpadding="0" cellspacing="0">
                    	<tr>
                        	<td width="103" align="left" class="perp" valign="top">
                                <a  href="http://my.7k7k.com/space/<s:property value='#threadReply.userId' />"  target="_blank"><img src="<s:property value='userMap.get(#threadReply.userId).icon_m'/>" /></a>
                                <a href="http://my.7k7k.com/space/<s:property value='#threadReply.userId' />" class="show"  target="_blank"><s:property value="userMap.get(#threadReply.userId).nick" /></a>
                            </td>
                            <td  align="left" class="con" valign="top">
                                <div id="content_<s:property value='#threadReply.id'/>" class="contentDiv">
                                	<s:if test="#threadReply.deleted == 0">
                                		<s:property value="#threadReply.content" escape="false" />
                                	</s:if>
                                	<s:else>
                                		该回复已被删除
                                	</s:else>
                                </div>
                                <div class="clearB"></div>
                                <div class="fr">回复于:<s:date name="#threadReply.createTime" format="yyyy-MM-dd HH:mm:ss" />&nbsp;&nbsp;&nbsp;&nbsp;
	                                <s:if test="#threadReply.deleted == 0">
		                                <s:if test="uId == null">
		                                	<a href="#" onclick="view(<s:property value="#threadReply.userId"/>)">只看该作者</a>
		                                </s:if>
		                                <s:else>
		                                	<a href="#" onclick="view('')">取消只看该作者</a>
		                                </s:else>
		                                <s:if test="thread.status == 0">|<a href="#replyArea" onclick="reply('<s:property value="#threadReply.floor" />', '<s:property value="userMap.get(#threadReply.userId).nick" />', 'content_<s:property value='#threadReply.id'/>')">回复</a></s:if>
	                                	<s:if test="#user.userId == #threadReply.userId">
		                                	<a href="#replyArea" onclick="edit('content_<s:property value='#threadReply.id'/>', '<s:property value='#threadReply.id'/>')">编辑</a>
		                                </s:if>
		                                <s:if test="#user != null && (#user.adminRole == 1 || #user.getBarRoleByBarId(thread.barId))">
		                                		<a href="#" onclick="replyOper('<s:property value="#threadReply.id"/>', 1)">删除</a>
		                                </s:if>
		                            </s:if>
		                            <s:else>
	                                	<s:if test="#user != null && (#user.adminRole == 1 || #user.getBarRoleByBarId(thread.barId))">
		                                	<a href="#" onclick="replyOper('<s:property value="#threadReply.id"/>', 0)">恢复</a>
		                                </s:if>
	                                </s:else>
                                </div>
                            </td>
                            <td width="37" valign="top" style="line-height:25px;"><s:property value="#threadReply.floor" />楼</td>
                        </tr>
                    </table>
                </td>
            </tr>
            </s:iterator>
        </table>
        <s:include value="include/pageNav.jsp"/>
        </form>
        <s:if test="banIp || (#user != null && (#user.status==1 || #user.isForbid()))">
			<span class="red">你已被禁言，不允许发贴!</span>
       	</s:if>
       	<s:else>
	        	<s:if test="thread.status == 0">
			        <form name="form2" id="form2" action="replyThread.html" method="post" onsubmit="return doPublish();">
			        <input type="hidden" name="threadId" value="<s:property value="threadId"/>"/>
			        <input type="hidden" name="replyId" id="replyId"/>
			        <ul class="mess" id="replyArea">
			            <li class="special">
			              <textarea id="content" name="content" maxlength="65534" style="width:800px;height:400px;visibility:hidden;"></textarea>
			              <br />
			              <span id="contentErr" class="red"></span>
			          </li>
			            <li>验证码：<input type="text" id="securityCode" name="securityCode" class="i_text" style="width:100px;" value="点击输入验证码" onblur="if(this.value=='') {this.value='点击输入验证码';this.style.color='#999999';}" onfocus="if(this.value=='点击输入验证码') {this.value='';}this.style.color='#000';" /><span class="dis_none"><img src="securityCode.html" id="verify"/>看不清？<a href="###" onclick="changeSecurityCode();">换一张</a></span><br/><span id="securityCodeErr" class="red"></span></li>
			            <li><input type="submit" value=" " class="sub_btn" /></li>
			        </ul>
			        </form>
				</s:if>
				<s:else>本贴已经被锁定，不允许回复！</s:else>
        </s:else>
    </div>
    <s:action name="right" executeResult="true"/>
    <div class="clearB"></div>
</div>
<s:include value="include/foot.jsp"/>
<s:if test="bar.image	!=null	&&	bar.image !='noImage'"> 
</div>
 </s:if>
</body>
<script language="javascript">
	$(function(){
		$('.contentDiv a').click(
			function(){
				if(confirm('链接可能是不安全链接,确定要跳转吗?')){
					return true;
				}else{
					return false;
				}
			});
	});

    function doSearch(pageNumber, totalItem){
		if(pageNumber <= 0){
			pageNumber = 1;
		}	
		$("#toPage").val(pageNumber); 
		$("#form1").submit(); 
	}
	
	function doThreadOper(action, flag){
		var url;
		if(action == 0){
			url = "ajaxStickyThread.html";
		}else if(action == 1){
			url = "ajaxDigestThread.html";
		}else if(action == 2){
			url = "ajaxLockThread.html";
		}else if(action == 3){
			url = "ajaxDeleteThread.html";
		}else{
			return;
		}		
		if(flag != 0 && flag != 1){
			return;
		}		
		$.getJSON(url, {"threadId":<s:property value="threadId"/>, "flag":flag}, function(result)	{
			if ($.trim(result.isSuccess)=="1"){
				//刷新当前页面				
				alert("操作成功！");
				window.location.reload();
			}else{
				alert("操作失败，" + result.error);
			}
		}, "json");
	}

	function replyOper(id, oper){
		var url = "ajaxReplyOper.html";
		$.getJSON(url, {"replyId":id, "oper":oper}, function(result)	{
			if ($.trim(result.isSuccess)=="1"){
				//刷新当前页面				
				alert("操作成功！");
				window.location.reload();
			}else{
				alert("操作失败，" + result.error);
			}
		}, "json");
	}

	function view(userId){
		$("#uId").val(userId);
		$("#form1").submit();
	}

	//点击图片更换验证码
	function changeSecurityCode(){
		$("#verify").attr("src","securityCode.html?timestamp="+new Date().getTime());
	}

	var count = 0;
	//验证发贴
	function doPublish(){
		if(count != 0){
			alert("请求提交中.请稍候.");
			return false;
		}
		$("#contentErr").html("");
		$("#securityCodeErr").html("");
		//验证内容
		if(editor.html() == ""){
			$("#contentErr").html("帖子内容不能为空");
			return false;
		}
		if(editor.html().length > 65534){
			$("#contentErr").html("帖子内容不能超过65534个字");
			return false;
		}
		<s:if test="#user != null && !#user.getBarRoleByBarId(barId)">
		var hanzi = editor.html().match(/[^\x00-\xff]/ig);
		hanziLength = 0;
		if(hanzi != null){
			hanziLength = hanzi.length;
		}    
		if(hanziLength < 8){
			$("#contentErr").html("内容不能少于8个汉字");
			return false;	
		}	
		if(editor.text().length <= 0){
			$("#contentErr").html("请不要发布水贴");
			return false;	
		}
		</s:if>
		
		//验证验证码
		var securityCode = $("#securityCode").val();
		if(securityCode == "" || securityCode == "点击输入验证码"){
			$("#securityCodeErr").html("验证码不能为空");
			return false;
		}
		//（同步)ajax请求
		var flag = false;
	 	$.ajax({
	    	type: "get",
	    	url: "ajaxVerifySecurityCode.html",
	    	data: {"securityCode":securityCode},
			async:false,
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			cache: false,			
	    	beforeSend:function(){},
	   		success: function(result)	{
						if ($.trim(result.isSuccess)=="1"){		
							flag = true;
						}else{				
							$("#securityCodeErr").html("验证码错误");
						}
					 },
	    	complete:function(){}
		});
		
		if(flag){
			count ++;
			return true;
		}else{
			return false;
		}
	}

	function edit(contentId, replyId){
		var content = $('#' + contentId).html();
		editor.html('' + content);
		$("#replyId").val(replyId); 
	}	

	function reply(floor, nick, contentId){
		var content = $('#' + contentId).html();
		editor.html('回复：' + floor + '楼 (' + nick + ')<br/>' + content + '<br/><br/>');
	}
</script>
</html>
